
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, logout, login
from django.core.mail import send_mail as send
from django.conf import settings

from forms import *

def index(request):
    resume = []
    profile = { 'header': 'Objective',
                'body': [{'header':' ', 'body': '''I am a 29 year old web applications developer working out of 
                Columbia, MD. I have been developing web appications from conception to deployment for the past 
                5 years. I enjoy working on all aspects of the web software developement life cycle, front and 
                back ends, and I welcome the unique challenge that web applications provide.'''}]}
    
    resume.append(profile)

    profile = { 'header': 'Skills',
                'body': [] }

    blocks = {'header': 'Proficient in: ',
                'body' : '''Python, C++, HTML, CSS, PostgreSQL and AJAX</br>
                            Django and Monty Web Development Frameworks.</br>
                            Eclipse, Ultraedit, VI, VIM, Emacs, Xemacs, PICO, NANO and other Editors.</br>
                            Javascript along with Jquery, Prototype, Dojo and Mochikit Javascript libraries.</br>
                            GIMP, Photoshop, Frontpage and other freeware tools to enhance web page design.</br>
                            Worked extensively using CVS, SVN, GiT and Mercurial version control systems.</br>
                            Working in Windows and Linux environments.</br>'''}
    profile['body'].append(blocks)

    blocks = {'header': 'Familiar with:',
                'body' : '''C, PERL.</br>
                            Setting up web servers with Apache</br>
                            Web reporting using Jasper Reports.</br>
                            CoffeeScript, HAML, JIT, Stylus'''}
    profile['body'].append(blocks)
                                
    blocks = {'header': 'Other Skills:',
                'body' : '''Strong analytical skills.</br>
                            Strong oral and written communication skills.</br>
                            Speak 2 other languages (Amharic and Hindi).</br>
                            Strong science background with focus on Biology due to my Bio-Informatics Degree.</br>
                            Strong knowledge of PC systems, both hardware and software. A+ certified.</br>'''}

    profile['body'].append(blocks)
    resume.append(profile)



    profile = { 'header': 'Professional Experience',
                'body': [] }

    blocks = {'header': 'ARINC Annapolis MD, 03/2012 - Present',
              'body' :  '''Developed Web applications using Python, ZOPE, Django.</br>
                            Worked with custom web framework developed in house called WebElements.</br>
                            Front-end, Back-end developement along with support and Maintenance of Web applications.</br>'''}

    profile['body'].append(blocks)

    blocks = {'header': 'White Oak Technologies INC. Silver Spring MD, 03/2011 - 03/2012',
                'body' : '''Developed Web applications using Monty and Django Web Framework.</br>
                            Support and Maintenance of Web applications.</br>
                            Front-end development using HTML, CSS and Javscript using Dojo and JQuery libraries.</br>
                            Back-end development using Python, Oracle SQL and extensive AJAX to interact directly with the front-end and other web services.</br>
                            Coffee script, HAML, JIT, Stylus are plugins I have used in some of my projects.</br>'''}
    profile['body'].append(blocks)
                                
    blocks = {'header': 'Information Management Services INC. Silver Spring MD, 02/2008 - 03/2011',
                'body' : '''Developed Web applications from start to finish including deployment.</br>
                            Met with clients to obtain all needs requirements for projects.</br>
                            Involved in design, analysis and implementation of the application.</br>
                            Primarily used the Django framework for web development in conjunction with Python.</br>
                            Front-end development using HTML, CSS and Javascript.</br>
                            Back-end development using Python, PostgreSQL and AJAX.</br>
                            Deployment of applications on our local linux servers.</br>
                            Responsible for testing, setting up unit tests and quality control of the application.</br>
                            Did research and implementation on adding several web based tools to sites such as Text editors, file handling mechanisms, security upgrades, user management tools etc.</br>
                            Added custom libraries to local applications to work with company specific tasks.</br>
                            Provide training for staff members on usage of sites developed for internal use.</br>'''}

    profile['body'].append(blocks)
    resume.append(profile)

    profile = { 'header': 'Education',
                'body': [{'header':'University Of Maryland Baltimore County (UMBC)', 'body': '''Bachelor of Science: Major Bioinformatics, Minor Computer Science'''}]}
    
    resume.append(profile)

    return render_to_response('index.html', locals())

def user_login(request):
    form = AuthenticationForm()
    if request.method == 'POST':
        form = AuthenticationForm(request.POST)
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        user = authenticate(username=username, password=password)
        if user is None:
            message = 'Your username and password didn\'t match. Please try again.'
        else:                
            login(request, user)
            if request.POST.get('home', None):
                return HttpResponseRedirect('/admin')
    return render_to_response('login.html', locals())

def user_logout(request):
    logout(request)
    return HttpResponseRedirect( request.META.get('HTTP_REFERER', None) or '/')

def register_user (request):
    form = RegistrationForm()
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            first_name      = request.POST.get('first_name', None)
            last_name       = request.POST.get('last_name', None)
            email           = request.POST.get('email', None)
            username        = request.POST.get('username', None)
            password        = request.POST.get('password', None)
            retype_password = request.POST.get('retype_password', None)
            
            user = User.objects.create(first_name=first_name , last_name=last_name , email=email , username=username)
            user.set_password(password)
            user.save()
            if user is None:
                message = 'Registration Failed. Please try again.'
            else:
                return render_to_response('confirmation.html', {'message': 'Registration is Complete.'})  
    return render_to_response('register.html', locals())
